package com.adong.test;

import com.adong.test.pojo.User;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.junit.Test;

/**
 * @author adong
 */

public class test {


    @Test
    public void test() {
        //创建configuration对象对应着,对应着hibernate基本配置和映射配置 configure();里面可以填核心配置文件名
        Configuration configuration =new Configuration().configure();
        System.out.println(configuration);
        //创建SessionFactory对象
        SessionFactory sessionFactory = configuration.buildSessionFactory();
        //创建Session对象
        Session session = sessionFactory.openSession();
       /* User user = new User();
        user.setUserName("adong");
        //执行保存操作
        session.save(user);*/
        User user = session.get(User.class, 1);
        System.out.println(user);
        //开启事务并提交
        session.beginTransaction().commit();

        session.close();
        sessionFactory.close();

    }
}
